<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Form Layouts</title>

    <link href="/public/js/summernote/dist/summernote.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/public/js/imageuploader/styles.imageuploader.css" />

    <!--nestable css-->
    <link rel="stylesheet" type="text/css" href="/public/js/nestable/jquery.nestable.css" />

    <!--file upload-->
    <link rel="stylesheet" type="text/css" href="/public/css/bootstrap-fileupload.min.css" />

    <link rel="stylesheet" type="text/css" href="/public/js/bootstrap-select-1.12.4/dist/css/bootstrap-select.css" />

    <link href="/public/js/iCheck/skins/flat/green.css" rel="stylesheet">

<!--    引入jqeditable裤-->
    <link rel="stylesheet" type="text/css" href="dist/jquery-editable-select.css"/>

    <!--    引入Select2-->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" />
    <?php $this->load->view('library/header');?>
    <style type="text/css">
        .p_supp_link {
            margin-bottom: 30px;
        }
        .sku_color,.sku_size {
            margin-top: 20px;
        }
        .none{
            display: none;
        }
        .hide_pic{
            display: none;
            position: fixed;
            padding: 0 !important;
            z-index: 9;
            top: 20%;
            width: 50%;
            height: 60%;
            background-color: white;
            border: 0 !important;
            border-radius: 6px;
            overflow: hidden;

        }
        .zhezhao{

            display: none;
            position: absolute;
            z-index: 5;
            top: 0;
            background-color:rgba(0,0,0,0.2);

            width: 36000px;
            height: 10000px;
        }
        .head-hk{
            height: 42px;
            background-color: darkseagreen;
        }
        .cuohao {
            font-size: 32px !important;
            margin-right: 10px;
            line-height: 42px !important;
        }
        .pic_click1{
            border: 1px solid #DDDDDD;
            border-radius: 5px;
            overflow: hidden;
            width: 35px;
            height: 35px;
        }
        .col-lg-4{
            display: flex;
        }
        .col-lg-4 input[type=radio]{
            margin: 10px 8px 0;
        }
        .col-lg-2 .input-group{
            padding-top: 3px;
        }
        .col-lg-2 .input-group  input[type=radio]{
            margin: 6px 7px 1px;
            width: 16px;
            height: 16px;
            vertical-align: text-bottom;
        }
        .modal-body img {
            width: 100%;
            max-height: none;
        }
        .img-rounded {
            overflow: hidden;
        }
        .img-rounded img {
            width: 35px;
            padding: 0;
        }
        .add_img {height: 160px;
            overflow: hidden;}

        .a-box{
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
        }
        .remove-x{
            height: 28px;
            line-height: 28px;
            margin: 3px 8px;
            padding: 0 9px;
            background-color: silver;
            color: black;
        }
        .select2{
            width: 381px;
            margin-left: 15px;
        }
        .select2 .select2-selection{
            height: 32px;
        }
        .select2 .select2-selection .select2-selection__placeholder{
            color: currentColor;
            margin-left: 8px;
        }
    </style>
</head>

<body class="sticky-header">

<section>
    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                产品编辑
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">Forms</a>
                </li>
                <li class="active"> Forms Layouts </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper">
            <!-- page start-->

            <div class="row">
                <div class="col-lg-12">

                    <section class="panel">
                        <header class="panel-heading custom-tab turquoise-tab">
                            <ul class="nav nav-tabs">
                                <li class="active">
                                    <a href="#home2" data-toggle="tab">基础信息</a>
                                </li>
                                <li class="">
                                    <a href="#profile2" data-toggle="tab">图片信息</a>
                                </li>
                                <li class="">
                                    <a href="#about2" data-toggle="tab">SKU信息</a>
                                </li>

                                <li class="cont-form">
                                    <a href="#contact2" data-toggle="tab">产品描述</a>
                                </li>
                            </ul>
                        </header>
                        <div class=" form">
                            <form class="cmxform form-horizontal adminex-form" id="commentForm" enctype="multipart/form-data" method="post" action="">
                                <div class="panel-body">
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="home2">
                                            <div class="form-group ">
                                                <label for="cemail" class="control-label col-lg-2">货号</label>
                                                <div class="col-lg-3">
                                                    <p style="line-height: 30px; margin: 0;"><?php echo $prepare['goods_sn'];?></p>
                                                </div>
                                            </div>
                                            <div class="form-group ">
                                                <label for="cname" class="control-label col-lg-2">商品名称<a href="#" class="zhuanhaun">转换</a></label>
                                                <div class="col-lg-10">
                                                    <input class=" form-control" value="<?php echo $prepare['title'];?>" name="goods_name" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group ">
                                                <label for="cname" class="control-label col-lg-2">商品中文名称</label>
                                                <div class="col-lg-10">
                                                    <input class=" form-control" value="<?php echo $prepare['cn_name'];?>" name="cn_name" type="text" />
                                                    <p style="line-height: 24px; padding-top: 10px; margin: 0;"><?php echo $goods_supp['cn_name'];?>&nbsp;&nbsp;&nbsp;<a target="_blank" href="<?php echo $goods_supp['supp_url'];?>">进入1688详情>></a></p>
                                                </div>
                                            </div>


                                            <div class="form-group ">
                                                <label for="cname" class="control-label col-lg-2">供应商名称</label>
                                                <div class="col-lg-4">
                                                    <!--                                            Select2-->
                                                    <div class="form-group ">

                                                            <select id="area" class="select1 dsfd form-control"  name="suppliers_id">
                                                                <option></option>

                                                            </select>
                                                    </div>
                                                </div>
                                            </div>


                                            <div class="form-group ">
                                                <label for="curl" class="control-label col-lg-2">商品类型</label>
                                                <div class="col-lg-3">
                                                    <select name="type_id" class="form-control">
                                                        <option>选择类型</option>
                                                        <?php foreach ($type_option as $type_id => $type_name) :?>
                                                            <option <?php echo $prepare['type_id'] == $type_id ? 'selected="selected"' : '';?> value="<?php echo $type_id;?>"><?php echo $type_name;?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group ">
                                                <label for="curl" class="control-label col-lg-2">产品重量</label>
                                                <div class="col-lg-2">
                                                    <div class="input-group">
                                                        <input type="text" value="<?php echo $prepare['goods_weight'];?>" name="goods_weight" class="form-control">
                                                        <span class="input-group-addon">G</span>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group ">
                                                <label for="curl" class="control-label col-lg-2">价格地方受速度</label>
                                                <div class="col-lg-2">
                                                    <div class="input-group">
                                                        <span class="input-group-addon">$</span>
                                                        <input type="text" value="<?php echo $prepare['shop_price'];?>" name="shop_price" class="form-control" placeholder="售价">
                                                    </div>
                                                </div>
                                            </div>

                                            <!--添加标签选项框-->
                                            <div class="form-group ">
                                                <input type="hidden" for="cname" class="control-label col-lg-2 form-control control-label " name="tags">
                                                <label for="curl" class="control-label col-lg-2 zjijian">标签</label>
                                                <div class="col-lg-3">
                                                    <select name="tag" class="form-control  selectpicker " id="aaa"  data-live-search="true">
                                                        <?php foreach ($tags as $type_id => $type_name) :?>
                                                            <option value="<?php echo $type_name['id'];?>"><?php echo $type_name['tags_name'];?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                    <div class="a-box"></div>
                                                </div>

                                            </div>
                                            

                                            <div class="form-group ">
                                                <label for="curl" class="control-label col-lg-2">质检结果

                                                </label>
                                                <div class="col-lg-2">
                                                    <div class="input-group">
                                                        <input type="radio"  <?php if($prepare['is_testing'] == 1){echo "checked='checked'";}?> name="is_testing" value='1'>合格
                                                    </div>
                                                </div>
                                                <div class="col-lg-2">
                                                    <div class="input-group">
                                                        <input type="radio" <?php if($prepare['is_testing'] == 2){echo "checked='checked'";}?> name="is_testing" value='2'>不合格
                                                    </div>
                                                </div>
                                                <div class="col-lg-2">
                                                    <div class="input-group">
                                                        <input type="radio"
                                                               <?php if($prepare['is_testing'] && $prepare['is_testing'] == 3){echo "checked='checked'";}
                                                               if(!$prepare['is_testing']){echo "checked='checked'";}?>name="is_testing" value='3'>待质检
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group" >
                                                <label class="col-sm-2 col-sm-2 control-label" >采购员</label >
                                                <div class="col-sm-3" >
                                                    <select name="purchase_id" class="form-control" id="purchaseId">
                                                        <option value="0" >选择采购员</option >
                                                        <?php foreach ($purchase as $k => $val): ?>
                                                            <option value="<?php echo $val['e_id']; ?>" ><?php echo $val['purchase_name']; ?></option >
                                                        <?php endforeach; ?>
                                                    </select >
                                                </div >
                                            </div >
                                        </div>
                                        <div class="tab-pane" id="profile2">
                                            <?php if ($goods_album) :?>
                                                <div class="uploader__box js-uploader__box l-center-box dd bo" id="nestable_list_1">
                                                    <ol class="dd-list js-uploader__file-list uploader__file-list">
                                                        <?php $i = 0; foreach ($goods_album as $k => $image) :?>
                                                            <li class="uploader__file-list__item dd-item" data-id="<?php echo $i+1;?>" data-sku-id="<?php echo $image['album_id'];?>" data-index="<?php echo $i;?>">
															<span class="uploader__file-list__thumbnail dd-handle">
																<img class="thumbnail1" src="<?php echo $image['original_img'];?>">
															</span>
                                                                <span class="uploader__file-list__text">timg-2.jpeg</span>
                                                                <span class="uploader__file-list__size">102 KB</span>
                                                                <span class="uploader__file-list__button"><button class="uploader__icon-button js-upload-remove-button fa fa-times" data-index="<?php echo $i;?>"></button></span>
                                                            </li>
                                                            <?php $i++; endforeach;?>
                                                    </ol>
                                                    <div class="js-uploader__contents uploader__contents uploader__hide"></div>
                                                </div>
                                                <p class="js-uploader__further-instructions uploader__further-instructions"></p>
                                            <?php else:?>
                                                <div class="uploader__box js-uploader__box l-center-box dd" id="nestable_list_1">
                                                    <ol class="dd-list js-uploader__file-list uploader__file-list"></ol>
                                                    <div class="js-uploader__contents uploader__contents"></div>
                                                </div>
                                                <p class="js-uploader__further-instructions uploader__further-instructions uploader__hide"></p>
                                            <?php endif;?>
                                        </div>
                                        <div class="tab-pane" id="about2">
                                            <div class="supp_sku">
                                                <div class="col-lg-6 sku_color">
                                                    <div class="form-group">
                                                        <label for="curl" class="control-label col-lg-2">商品颜色</label>
                                                        <div class="col-lg-9">
                                                        <?php foreach ($goods_option[1] as $row):?>
                                                        <div class="minimal single-row" style="margin-bottom: 15px;">
                                                            <a href="#myModal" data-toggle="modal" class="img-rounded option-<?php echo $row['option_id'];?>" data-id="<?php echo $row['option_id'];?>" style="float: left; margin-right: 15px; width: 35px; height: 35px; background-color: #8888;" >
                                                                <?php if ($row['album_url']):?>
                                                                <img src="<?php echo $row['album_url'];?>" />
                                                                <?php endif;?>
                                                            </a>
                                                            <input style="float: left; width: 200px;" value="<?php echo $row['option_value'];?>" name="aliyun_sku[ali_color][<?php echo $row['option_id'];?>]" readonly = "readonly" class="form-control sunjian_ali_color">
                                                            <div class="clearfix"></div>
                                                        </div>
                                                        <?php endforeach;?>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-lg-6 sku_size">
                                                    <div class="form-group">
                                                        <label for="curl" class="control-label col-lg-2">商品尺码</label>
                                                        <div class="col-lg-9">
                                                        <?php foreach ($goods_option[2] as $row):?>
                                                            <div class="minimal single-row" style="margin-bottom: 15px;">
                                                                <input style="width: 200px;" value="<?php echo $row['option_value'];?>" name="aliyun_sku[ali_size][<?php echo $row['option_id'];?>]" readonly = "readonly" class="form-control sunjian_ali_size">
                                                            </div>
                                                        <?php endforeach;?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="tab-pane" id="contact2">
                                            <div class="form-horizontal ">
                                                <div class="form-group">
                                                    <div class="col-md-12">
                                                        <textarea id="summernote" name="summernote" class="form-control" cols="4" rows="9"><?php echo $prepare['body_html'];?></textarea>
                                                        <div class="goods_attr">
                                                            <button type="button" class="btn btn-info btn-sm btn-add-row">添加行</button>
                                                            <button type="button" style="margin-left: 5px" class="btn btn-info btn-sm btn-add-col">添加列</button>
                                                            <button type="button" style="margin-left: 5px" class="btn btn-info btn-sm centimeter">点击转换为厘米</button>
                                                            <?php if ($prepare['goods_attr']):?>
                                                                <table class="goods_attr_table table table-bordered" style="margin-top: 10px;">
                                                                    <thead>
                                                                    <tr>
                                                                        <?php foreach ($prepare['goods_attr']['attr_title'] as $k_title => $attr_title): ?>
                                                                            <th><input class="form-control" name="attr_title[]" value="<?php echo $attr_title; ?>" /></th>
                                                                        <?php endforeach;?>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    <?php foreach ($prepare['goods_attr']['attr_val'][0] as $k_val => $attr_val):?>
                                                                        <tr>
                                                                            <?php foreach ($prepare['goods_attr']['attr_title'] as $_k_title => $attr_title): ?>
                                                                                <td><input class="form-control" name="attr_val[<?php echo $_k_title;?>][]" value="<?php echo $prepare['goods_attr']['attr_val'][$_k_title][$k_val];?>" /></td>
                                                                            <?php endforeach;?>
                                                                            <td class="row-del"><a href="javascript:;">删除</td></tr>
                                                                        </tr>
                                                                    <?php endforeach;?>
                                                                    <tr class="tr-del">
                                                                        <td></td>
                                                                        <?php foreach ($prepare['goods_attr']['attr_title'] as $_k_title => $attr_title): if ($_k_title == 0) {continue;} ?>
                                                                            <td><a href="javascript:;">删除</a></td>
                                                                        <?php endforeach;?>
                                                                    </tr>
                                                                    </tbody>
                                                                </table>
                                                            <?php else: $_k_title = 0;?>
                                                                <table class="goods_attr_table table table-bordered" style="margin-top: 10px;">
                                                                    <thead>
                                                                    <tr>
                                                                        <th><input class="form-control" name="attr_title[0]" value="SIZE(IN)" /></th>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody class="not-add">
                                                                    </tbody>
                                                                </table>
                                                            <?php endif;?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <footer class="panel-footer">
                                    <button type="submit" name="handle_type" value="0" class="btn btn-post pull-right btn-big">提交信息</button>
                                    <ul class="nav nav-pills p-option"></ul>
                                </footer>
                            </form>
                        </div>
                    </section>
                </div>
            </div>
            <!-- page end-->
        </section>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">Form Tittle</h4>
            </div>
            <div class="modal-body">
                <div class="row"></div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('library/footer');?>
<!--编辑器-->
<script src="/public/js/summernote/dist/summernote.js"></script>
<script src="/public/js/summernote/dist/lang/summernote-zh-CN.js"></script>

<script src="/public/js/imageuploader/jquery.imageuploader.js"></script>

<!--icheck -->
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>

<script src="/public/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js"></script>

<script src="/public/js/nestable/jquery.nestable.js"></script>
<script src="/public/js/nestable-init.js"></script>

<script src="/public/js/express-art-template-master/template-web.js"></script>
<script type="text/html" id="color_temp">
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px; margin-left: -30px;">
        <div class="col-lg-6">
            <img width="35" src="<%=items[i].imageUrl%>" class="img-rounded" style="float: left; margin-right: 15px;" />
            <input style="float: left; width: 200px;" value="<%=items[i].name%>" name="aliyun_sku[ali_color][]" readonly = "readonly" class="form-control sunjian_ali_color">
        </div>
        <div class="col-lg-5">
            <select name="aliyun_sku[color][]" class="option-color form-control sunjian_color supp_sku_color">
                <option value="">选择颜色</option>
                <?php foreach ($color_option as $k => $color) :?>
                    <option value="<?php echo $k;?>"><?php echo $color;?></option>
                <?php endforeach;?>
            </select>
        </div>
    </div>
    <% } %>
</script>
<script type="text/html" id="size_temp">
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px;">
        <div class="col-lg-4">
            <input value="<%=items[i].name%>" name="aliyun_sku[ali_size][]" readonly = "readonly" class="form-control sunjian_ali_size">
        </div>
        <div class="col-lg-6">
            <select name="aliyun_sku[size][]" class="option-size form-control sunjian_size supp_sku_size">

                <option value="">选择尺码</option>
                <?php foreach ($size_option as $size) :?>
                    <option value="<?php echo $size;?>"><?php echo $size;?></option>
                <?php endforeach;?>
            </select>
        </div>
    </div>
    <% } %>
</script>
<script type="text/javascript">
    $('.zhuanhaun').click(function(){
        var goods_name = $("input[name='goods_name']").val();
        $("input[name='goods_name']").val(replaceStr(goods_name));
    })

    function replaceStr(str) {
        var strTemp = ""; //新字符串
        for(var i = 0; i < str.length; i++) {
            if(i == 0) {
            strTemp += str[i].toUpperCase(); //第一个
            continue;
            }
            if(str[i] == " ") { //空格后
            strTemp += " ";
            strTemp += str[i + 1].toUpperCase();
            i++;
            continue;
            }
            if(str[i] == "-") { //-后
            strTemp += "-";
            strTemp += str[i + 1].toUpperCase();
            i++;
            continue;
            }
            strTemp += str[i];
        }
        return strTemp;
    }



    $(function () {

        $('.selectpicker').selectpicker({
            size: 6
        });

        $('#summernote').summernote({
            tabsize: 2,
            height: 300,
            lang: 'zh-CN'
        });

        state = {
            fileBatch: [],
            isUploading: false,
            isOverLimit: false,
            listIndex: 0
        };
        $('.js-uploader__box').uploader({
            'selectButtonCopy':'请选择或拖拽文件',
            'instructionsCopy':'你可以选择或拖拽多个文件',
            'submitButtonCopy':'上传选择的文件',
            'furtherInstructionsCopy':'你可以选择或拖拽更多的文件',
            'secondarySelectButtonCopy':'选择更多的文件'
        });

        $('.get-goods').on('click', function () {

            var supp = $(this).parents('.addsupp').find('.curl').val();

            thisg = $(this);

            $(this).html('获取中...');
            var supp_id = $('.selectpicker').val();
            $.post("<?php echo base_url('PrepareGoods/ajax_ali_goods');?>", {ali_url: supp,supp_id:supp_id}, function (aliData) {

                var result_color = '', result_size = '';
                var data = aliData.data;

                thisg.parents('.addsupp').find('.supp_sn').val(data.ali_sn);
                thisg.parents('.addsupp').find('.in_price').val(data.ali_price);
                thisg.parents('.addsupp').find('.g_supp_id').val(data.g_supp_id);

                $('.supp_name').val(data.title);

                if (data.skuProps) {
                    for (var x in data.skuProps) {

                        var obj = {
                            items: data.skuProps[x].value
                        };

                        if (data.skuProps[x].prop === '颜色') {
                            result_color += template('color_temp', obj);
                        } else if (data.skuProps[x].prop === '尺码') {
                            result_size += template('size_temp', obj);
                        }
                    }
                    $('.supp_sku .sku_color').html(result_color);
                    $('.supp_sku .sku_size').html(result_size);
                    $('.flat-green input').iCheck({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green'
                    });
                }


            }, 'json');
        });

        $('.img-rounded').on('click', function () {
            $('#myModal .modal-body .row').html('');
            var data_goods_id = $(this).attr('data-id');
           $('.uploader__file-list__item').each(function (i) {

               var data_id = $(this).attr('data-index');
               var html = '<div style="text-align: center;" data-goods-id="' + data_goods_id + '" class="col-lg-3 add_img" data-id="' + data_id + '">' + $(this).find('.uploader__file-list__thumbnail').html() + '</div>';
               $('#myModal .modal-body .row').append(html);
           });
        });

        $('.modal-body').on('click', '.add_img', function () {
            var data_id = $(this).attr('data-id');
            var data_goods_id = $(this).attr('data-goods-id');
            var html = '<input type="hidden" name="aliyun_sku[color_img]['+ data_goods_id + ']" value="' + data_id + '" />';
            $('.option-'+data_goods_id).html($(this).html()+html);
        });

        var yi = <?php echo $_k_title + 1;?>;
        $('.cont-form').click(function () {

            size = [];

            $('.sku_size .sunjian_ali_size').each(function(index, element) {
                size[$(this).val()] = $(this).val();
            });
            for (x in size)
            {
                $('.goods_attr_table tbody.not-add').append('<tr><td><input class="form-control" name="attr_val[0][]" value="' + size[x] + '" /></td><td class="row-del"><a href="javascript:;">删除</td></tr>');
            }
            $('.goods_attr_table tbody.not-add').append('<tr class="tr-del"><td></td></tr>');
            $('.goods_attr_table tbody.not-add').removeClass('not-add');
        });

        $('.btn-add-col').click(function () {
            $('.goods_attr_table thead tr').append('<th><input class="form-control" name="attr_title['+ yi +']" value="" /></th>');
            $('.goods_attr_table tbody tr:not(.tr-del) td:last-child').before('<td><input class="form-control" name="attr_val['+ yi +'][]" value="" /></td>');
            $('.goods_attr_table tbody tr.tr-del').append('<td><a href="javascript:;">删除</a></td>');

            yi++;

        });
        $('.btn-add-row').click(function () {
            var html = $('.goods_attr_table tbody tr:not(.tr-del):last').html();
            $('.goods_attr_table tbody tr.tr-del ').before('<tr>'+html+'</tr>');
        });

        $('.tr-del td a').live("click",function(){
            var del=confirm("您确定要删除此条记录？");
            if(del==true){
                var a_eq = $(this).parent('td').index();

                $('.goods_attr_table thead tr th:eq(' + a_eq + ')').remove();
                $('.goods_attr_table tbody tr').each(function () {
                    $(this).find('td:eq('+ a_eq +')').remove();
                });
            }else{
                return false;
            }
        });

        $('.row-del a').live('click', function () {
            var del=confirm("您确定要删除此条记录？");
            if(del==true) {
                var a_eq = $(this).parents('tr').index();
                $('.goods_attr_table tbody tr:eq(' + a_eq + ')').remove();
            } else {
                return false;
            }
        });

        //获取货号
        $('#admin_id').change(function () {

            $.post('<?php echo base_url('PrepareGoods/get_goods_sn');?>',{admin_id:$(this).val()},function (goods_sn) {
                $('#goods_sn').val(goods_sn);
            }, 'text');
        });

        $('#commentForm').submit(function () {
            $('.panel-footer .btn-big').attr('disabled','disabled').addClass('btn-submit-disabled').html('正在提交，请稍等...');


            var data = new FormData(this);
            $(".uploader__file-list__item").each(function (i) {
                var index = $(this).attr('data-index');
                for (var i = 0; i < state.fileBatch.length; i++) {

                    if (state.fileBatch[i] && state.fileBatch[i].id === parseInt(index)) {
                        data.append('files'+index, state.fileBatch[i].file, state.fileBatch[i].fileName);
                        break;
                    }
                }
                data.append("files_sort["+index+"]", $(this).attr('data-sku-id'));
            });
            var tags = '';
            $('.remove-x').each(function(k,v){
                tags += ','+ $(this).attr('id');
            })
            data.append("tags",tags.substr(1));
            $.ajax({
                type: 'POST',
                url: '<?php echo base_url('PrepareGoods/set/prepare_id/'. $prepare['prepare_id'] . '/step/3');?>',
                data: data,
                success: function (data) {
                    if (data.status != 'success') {
                        swal({
                            title:   data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                        $('.panel-footer .btn-big').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
                    } else {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: data.stop ? data.stop : 1500,
                            showConfirmButton: false
                        }).then(function(isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('PrepareGoods/index_accurate?prepare_state=3');?>';
                        });
                        $('.panel-footer .btn-big').removeClass('btn-submit-disabled').html(data.info);
                    }

                },
                dataType:'json',
                cache: false,
                contentType: false,
                processData: false
            });
            setTimeout(function() {
                $('.panel-footer .btn-big').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
            }, 2000);
            return false;
        });

        // 点击按钮转换厘米英寸
        $(".centimeter").click (function(){
            // 循环每个input
            $('.goods_attr_table input').each(function (i) {

                // 获取每个val值
                var a =  $(this).val();

                // 如果里面有-
                if ((a.includes('-')) && (typeof($(this).attr("target"))=="undefined")){
                    // 把有横杠的转化为数组
                    arr = a.split("-");
                    // 乘以倍数并保留小数点
                    var b = [(arr[0]*2.54).toFixed(1),(arr[1]*2.54).toFixed(1)];
                    c =b.join("-");

                    $(this).attr({"value": c});
                    $(this).attr("target","_blank")
                }

                // 如果为数字
                else  if((!isNaN(a)) && (typeof($(this).attr("target"))=="undefined"))
                {
                    d = a*2.54;
                    d = d.toFixed(1);
                    $(this).attr({"value": d});
                    $(this).attr("target","_blank")
                }

            });
        });

    });

</script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js"></script>
<script>
    $(function () {
        // 供应商名称ajax传值
        var bbb =  new Array();
        $.ajax({
            type:"get",
            url:"<?php echo base_url("Suppliers/select_supp");?>",
            dataType:"json",
            async:false,
            success:function(data){
                console.log(data);
                // return false
                $.each(data,function (b,c) {
                    bbb.push({id : c.suppliers_id,text : c.suppliers_name});
                });
            },
            error:function(data){

            }
        });
        $(".select1").select2({
            data: bbb,
            placeholder:'请选择',//默认文字提示
            language: "zh-CN",//汉化
            allowClear: true//允许清空
        });
        $('#area').change(function(){
            var supp_id = $(this).val();
            $.ajax({
                type:'post',
                url:"<?php echo base_url("Suppliers/purchaseeid");?>",
                data:{
                    supp_id:supp_id,
                },
                success:function(msg){
                    // if(msg != 0){
                        $('#purchaseId').val(msg)
                    // }
                }
            })
        })
        $("#aaa").change(function () {

            var htmladd="";
            var id = $('#aaa option:selected') .val();
            $('.remove-x').each(function(k,v){
                var s_id = $(this).attr('id');
                if(id == s_id){
                    htmladd = 1;
                }
            })
            if(htmladd){
                return false
            }

            htmladd +='<div class="remove-x" id="'+id+'">';
            htmladd +=$('#aaa option:selected') .text();
            htmladd +="&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
            htmladd +="x";
            htmladd +=' </div>';
            $(".a-box").append(htmladd);
            $(".remove-x").on("click",function(){
                this.remove()
            });
        });

    })
</script>

</body>
</html>
